#include "Comm.hpp"

int main()
{
    Fifo fifo(Path);

    int rfd = open(Path,O_RDONLY);
    if(rfd < 0)
    {
        cerr << "open failed,error: " << errno << ",errstring: " << strerror(errno) << endl;
        return 1;
    }
    // 如果写端未打开，读端先打开，open的时候会阻塞，等待写端打开，读端open才会返回
    cout << "open success" << endl; 
    
    char buffer[1024];
    while(true)
    {
        ssize_t n = read(rfd,buffer,sizeof(buffer)-1);
        if(n > 0)
        {
            buffer[n] = 0;
            cout << "client say : " << buffer << endl;
        }
        else if(n == 0)
        {
            cout << "client quit,me too!!" << endl;
            break;
        }
        else
        {
            cerr << "read failed,error: " << errno << ",errstring: " << strerror(errno) << endl;
            break;
        }
    }

    close(rfd);
    return 0;
}